package com.laozhao.msas.view;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JWindow;

/*
 * Copyright 2009-2012 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Description:
 * <br/>网站: <a href="http://www.crazyit.org" mce_href="http://www.crazyit.org">疯狂Java联盟</a> 
 * <br/>Program Name: FaceWindow.java
 * <br/>Project Name: netgame
 * <br/>Date: 2010-2-6
 * @author  : leeyohn
 * @e-mail  : leeyohn@hotmail.com
 * @QQ      : 1417515725
 * @version : 1.0
 */

public final class FaceWindow extends JWindow
{
    //表情图片的数量
    private static final int FACE_COUNT = 8;

    //表情窗口的宽度长度
    private static final int FACE_WINDOW_WIDTH = 360;
    private static final int FACE_WINDOW_HEIGHT = 192;


    //静态表情图片数组
    private ImageIcon[] faces = new ImageIcon[FACE_COUNT];

    private JList faceList = new JList(faces);

    //加载所有表情图片
    private void initImage() 
    {
        for (int i = 0; i < FACE_COUNT; i++) 
        {
            faces[i] = new ImageIcon("img/" + i + ".png");
        }
    }

    public FaceWindow() 
    {
        initImage();
//        add(new JScrollPane(faceList), BorderLayout.CENTER);
//        faceList.setLayoutOrientation(JList.HORIZONTAL_WRAP);
        //设置表情列表可显示的行数
//        faceList.setVisibleRowCount(8);
        setLayout(new BorderLayout(5,5));
        JPanel toppanel = new JPanel();
        toppanel.setLayout(new FlowLayout(FlowLayout.TRAILING));
        JButton closeButton = new JButton("X");
        closeButton.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				System.out.println("close the windows!");
				setVisible(false);
				System.out.println("exit the system!");
				System.exit(0);
			}
		});
        toppanel.add(closeButton);
        toppanel.setBorder(BorderFactory.createTitledBorder("title"));
        toppanel.addMouseListener(new MouseAdapter() {
        	public void mousePressed(MouseEvent e){
//        		FaceWindow.setLocale(e.getX(),e.getY());
        	}
		});
        add(toppanel,BorderLayout.NORTH);
        JPanel mainPanel = new JPanel(new GridLayout(4,4));
        mainPanel.add(new JLabel("User Name"));
        mainPanel.add(new JTextField("admin"));
        mainPanel.add(new JLabel("User company"));
        mainPanel.add(new JTextField("HP Company"));

        mainPanel.add(new JLabel("User Name"));
        mainPanel.add(new JTextField("admin"));
        mainPanel.add(new JLabel("User company"));
        mainPanel.add(new JTextField("HP Company"));

        mainPanel.add(new JLabel("User Name"));
        mainPanel.add(new JTextField("admin"));
        mainPanel.add(new JLabel("User company"));
        mainPanel.add(new JTextField("HP Company"));

        mainPanel.add(new JLabel("User Name"));
        mainPanel.add(new JTextField("admin"));
        mainPanel.add(new JLabel("User company"));
        mainPanel.add(new JTextField("HP Company"));

        
        add(mainPanel,BorderLayout.CENTER);
//        setSize(FACE_WINDOW_WIDTH + 35, FACE_WINDOW_HEIGHT + 21);
        pack();
        setLocation(600, 480);
    }

    public static void main(String[] args)
    {
        new FaceWindow().setVisible(true);
    }
}
